home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
58606
/
58606.xpi
/
chrome
/
translator.jar
/
content
/
popup.js
< prev
next >
Wrap
Text File
|
2010-02-07
|
4KB
|
207 lines
(function(namespace, $)
{
namespace.Popup = function(doc)
{
this.doc = doc;
};
namespace.Popup.prototype = {
initialized: false,
doc: null,
el: null,
elMessage: null,
elNotice: null,
elTextarea: null,
css: {},
message: '',
notice: '',
visible: false,
init: function()
{
if(this.initialized) return;
// create popup element
this.createPopupElement();
this.initialized = true;
},
uninit: function()
{
this.reset();
this.el.remove();
this.el = null;
this.elMessage = null;
this.elNotice = null;
this.elTextarea = null;
this.css = {};
this.message = '';
this.notice = '';
this.visible = false;
this.initialized = false;
},
createPopupElement: function()
{
this.el = $('<div class="translator-popup"></div>', this.doc);
this.elMessage = $('<div></div>', this.doc).appendTo(this.el);
this.elNotice = $('<div></div>', this.doc).appendTo(this.el);
this.elTextarea = $('<textarea></textarea>', this.doc).appendTo(this.el).hide();
// style it
this.el.css({
background: '#D9C6B6',
border: '3px #784F2B ridge',
bottom: 'auto',
display: 'none',
height: 'auto',
left: 0,
margin: 0,
maxWidth: '500px',
maxWidth: '350px',
overflow: 'auto',
padding: 0,
position: 'fixed',
right: 'auto',
textAlign: 'left',
top: 0,
width: 'auto',
zIndex: 9999999999
});
this.elMessage.css({
color: '#111',
fontFamily: 'Helvetica, Arial, sans-serif',
fontSize: '14px',
padding: '5px 7px'
});
this.elNotice.css({
color: '#9D0505',
fontFamily: 'Helvetica, Arial, sans-serif',
fontSize: '14px',
fontStyle: 'italic',
padding: '5px 7px'
});
$('body', this.doc).append(this.el);
},
reloadCss: function()
{
this.el.css({
bottom: (this.css.x != undefined ? 'auto' : 0),
left: (this.css.x != undefined ? this.css.x : 'auto'),
maxHeight: (Math.min(this.doc.defaultView.innerHeight, 500) - 6/*border*/ - 20/*possible scrollbar*/) + 'px',
maxWidth: (Math.min(this.doc.defaultView.innerWidth, 350) - 6/*border*/ - 20/*possible scrollbar*/) + 'px',
right: (this.css.y != undefined ? 'auto' : 0),
top: (this.css.y != undefined ? this.css.y : 'auto')
});
},
setMessage: function(message)
{
if(!this.initialized) {
this.init();
}
// put message in textarea to handle all special chars
this.elTextarea[0].innerHTML = message;
// assign to message
this.message = this.elTextarea.val();
// update message element
this.elMessage.text(this.message);
},
setNotice: function(notice)
{
if(!this.initialized) {
this.init();
}
// assign to notice
this.notice = notice;
// update notice element
this.elNotice.text(this.notice);
},
showMessage: function()
{
if(!this.initialized) {
this.init();
}
// style for message
this.el.css({
borderColor: '#784F2B'
});
// call standard show function
this.show();
},
showError: function()
{
if(!this.initialized) {
this.init();
}
// style for error
this.el.css({
borderColor: '#C31919'
});
// call standard show function
this.show();
},
show: function()
{
if(!this.initialized) {
this.init();
}
if(!this.el) return;
this.reloadCss();
// show/hide translation element
this.elMessage[this.message.length ? 'show' : 'hide']();
// show/hide notice element
this.elNotice[this.notice.length ? 'show' : 'hide']();
if(!this.visible) {
this.visible = true;
this.el.show(250);
}
},
hide: function()
{
if(!this.el) return;
this.el.hide(100);
this.visible = false;
},
setPosition: function(x, y)
{
this.css.x = x + 5;
this.css.y = y + 5;
},
resetPosition: function()
{
this.css = {};
}
};
})(com.igorgladkov.translator, translatorJQuery);